home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / bas_int1.zip / FLOPSTAT.BAS < prev    next >
BASIC Source File  |  1991-07-19  |  5KB  |  145 lines

  1. '======================================================================
  2. ' Quick Basic Forum
  3. '   Date : 17-Jul-91
  4. '   From : Richard Attenborough
  5. 'Subject : Floppy Disk Status Check
  6.  
  7. 'I have been playing around with a way to check the status of a floppy
  8. 'disk without crashing my machine. I believe that I have created a
  9. 'routine to do this but I would appreciate it if those of you out there
  10. 'who know more about this than I do would check it over. I got the
  11. 'information about the interrupt used from the DOS PROGRAMMERS REFERENCE
  12. '2ND EDITION (HIGHLY recommended, it even has some QB source code in
  13. 'it!).
  14. '========================================================================
  15.  
  16.  
  17. DECLARE FUNCTION CheckFloppyStatus% (DriveNum%)
  18. '$INCLUDE: 'qb.bi'
  19.  
  20. x = CheckFloppyStatus%(0)
  21.  
  22. PRINT x
  23. END
  24.  
  25. FUNCTION CheckFloppyStatus% (DriveNum%)
  26. 'Interrupt 13h  Function 02h  Read Disk Sectors
  27. 'calling registers AH    = 02h (sets function)
  28. '                  AL    = number of sectors to transfer
  29. '                  ES:BX = Pointer to User's disk Buffer
  30. '                  CH    = Track number
  31. '                  CL    = Sector Number
  32. '                  DH    = Head Number
  33. '                  DL    = Drive Number (set bit 7 if checking the HD)
  34. 'Return Registers
  35. '               Carry flag is CLEAR if successful
  36. '                  AH    = 0
  37. '                  AL    = Number of Sectors Transferred
  38. '
  39. '               Carry Flag is SET if ERROR
  40. '                  AH    = Status Byte (see Error Table Below)  
  41. 'Note: When using this function with a  Hard Disk, the track number is 10
  42. '      rather than 8. The upper two bits are passed to the function in the
  43. '      high two bits of the CL register.
  44. '
  45. '       STATUS BITS CHART                                              error
  46. '                                                                       code
  47. '   bit          meaning                                               ------
  48. ' 76543210                                                     decimal
  49. ' .......1  Illegal command to driver                          =   1 =>   1
  50. ' ......1.  Address mark not located (bad sector)              =   2 =>   2
  51. ' ......11  Write Protected Disk                               =   3 =>   3
  52. ' .....1..  Requested sector not found                         =   4 =>   4
  53. ' .....11.  Diskette Change line active                        =   6 =>   5
  54. ' ....1...  DMA overrun                                        =   8 =>   6
  55. ' ....1..1  DMA attempt across 64k boundary                    =   9 =>   7
  56. ' ....11..  Invalid Media                                      =  12 =>   8
  57. ' ...1....  CRC error on disk read                             =  16 =>   9
  58. ' ..1.....  Controller Error                                   =  32 =>  10
  59. ' .1......  Seek Failure                                       =  64 =>  11
  60. ' 1.......  Disk Time out (failure to respond, drive not ready)=-128 =>  12
  61. '
  62. '
  63. ' calling convention    FDrivErr% = CheckFloppyStatus% (0)
  64. '
  65. ' Routine written by Richard Attenborough, July 1991. 
  66. ' Placed into the Public Domain, July 1991.
  67. ' I make no claim that this routine will do ANYTHING! I believe that it works
  68. ' but if you have problems with it then I can't help you.
  69.  
  70. DIM InRegs AS RegTypeX
  71. DIM OutRegs AS RegTypeX
  72.  
  73. JunkVar$ = SPACE$(1024)
  74.  
  75.  
  76. IF DriveNum% < 0 OR DriveNum% > 1 THEN
  77.    ' I have only created this routine for floppy disk use so I saw no need 
  78.    ' to allow drive letters other than A and B. Remember Hard Drive 0 = 128
  79.    ' asking for status of an invalid drive so return invalid drive code..-1
  80.    CheckFloppyStatus% = -1
  81.  
  82. END IF
  83.  
  84. InRegs.AX = &H2 * 256 + 0      'function 02 plus read zero sectors of data
  85.  
  86. InRegs.DX = &H0 * 256 + DriveNum%
  87.                                'Head zero+Drive #0 or 1 (floppy drive A or B)
  88.  
  89. InRegs.CX = &H1 * 256 + 1      'Set track and Sector to 0
  90.  
  91. InRegs.BX = SADD(JunkVar$)     'offset  Address of JunkVar (disk Buffer)
  92. InRegs.ES = VARSEG(JunkVar$)   'Segment Address of JunkVar
  93.  
  94. CALL InterruptX(&H13, InRegs, OutRegs)
  95.  
  96. CheckFloppyStatus% = 0
  97.  
  98. IF (OutRegs.FLAGS AND 1) = 1 THEN  ' checks CARRY flag
  99.  
  100.    AHREG = INT(OutRegs.AX / 256) 'set the value of AHREG to be the AH Register
  101.  
  102.    SELECT CASE AHREG  ' set the errorcode based on AHREG
  103.  
  104.           CASE IS < 0
  105.               ' Disk Time Out (failure to respond, drive not ready)
  106.               CheckFloppyStatus% = 12
  107.  
  108.           CASE 1, 2, 3, 4
  109.               CheckFloppyStatus% = AHREG
  110.     
  111.           CASE 6
  112.               CheckFloppyStatus% = 5
  113.       
  114.           CASE 8
  115.               CheckFloppyStatus% = 6
  116.  
  117.           CASE 9
  118.               CheckFloppyStatus% = 7
  119.  
  120.           CASE 12
  121.               CheckFloppyStatus% = 8
  122.  
  123.           CASE 16
  124.               CheckFloppyStatus% = 9
  125.  
  126.           CASE 32
  127.               CheckFloppyStatus% = 10
  128.  
  129.           CASE 64
  130.               CheckFloppyStatus% = 11
  131.  
  132.           CASE ELSE
  133.               PRINT "panic, a new and unknown error code has been detected"
  134.               PRINT AHREG; " is the errorcode"
  135.         END SELECT
  136.  
  137. END IF
  138.  
  139. 'PRINT "# of sectors read="; OutRegs.AX - (AHREG * 256)
  140. 'PRINT JunkVar$
  141. 'PRINT LEN(JunkVar$)
  142.  
  143. END FUNCTION
  144.  
  145.